AddItemWindow = function(){
	var this_window = this;
	
	var reloadComboBox = function(){
		hospitalCombo.store.reload();
		productCombo.store.reload();
		personCombo.store.reload();
		unitCombo.store.reload();
	};
	this.reloadComboBox = reloadComboBox;
	
	var save = function(){
		if(!form.form.isValid()){
			return false;
		}
		var params = form.form.getFieldValues();
		Ajax({
			url : "item/save.action",
			params : params,
			maskTarget : this_window,
			window : this_window,
			success : function(){
				setDetailPanel.getTopToolbar().init();
			}
		});
	}
	
	var hospitalCombo = new Combobox("item.hospital.id","医院名称","hospital");
	var productCombo = new Combobox("item.product.id","货品名称","product");
	var unitCombo = new Combobox("item.unit.id","货品单位","unit");
	var personCombo = new Combobox("item.person.id","相关人员","person",["id",{
		name : "name",
		convert : function(v,rec){
			return "(编号:"+ rec.id+") " + v;
		}
	}]);
	
	this.listeners = {
		hide : function(){
//			form.form.reset();
		},
		show : function(){
			reloadComboBox();
		}
	};
	
	var form = new Ext.form.FormPanel({
		frame : true,
		padding : 5,
		defaults : {
			labelAlign : "right",
			labelWidth : 60,
			defaults : {
				xtype : 'textfield',
				anchor : "95%",
				allowBlank : false
			}
		},
		items : [{
			xtype : "fieldset",
			title : "项目信息",
			items : [hospitalCombo,productCombo,personCombo,unitCombo]
		},{
			xtype : "fieldset",
			title : "销售信息",
			items : [{
				fieldLabel : "发货日期",
				name : "item.sellDate",
				xtype : "datefield",
				format : "Y/m/d"
			},{
				fieldLabel : "发货数量",
				name : "item.count",
				xtype : "numberfield"
//				allowNegative : false
				
			},{
				fieldLabel : "售价(元)",
				name : "item.sellPrice",
				xtype : "numberfield",
				allowNegative : false
			},{
				fieldLabel : "进价(元)",
				name : "item.buyPrice",
				xtype : "numberfield",
				allowNegative : false
			}]
		}]
	});
	AddItemWindow.superclass.constructor.call(this, {
		title : "添加新项目",
		iconCls : "add",
		width : 400,
		border : false,
		autoHeight : true,
		closeAction : "hide",
		modal : true,
		items : [form],
		buttons : [{
			text : "保存",
			handler : save
		},{
			text : "取消",
			handler : function(){
				this_window.hide();
			}
		}]
	});
};
Ext.extend(AddItemWindow, Ext.Window);
var addItemWindow = new AddItemWindow();